package models

import (
	"time"

	"gorm.io/gorm"
)

type User struct {
	ID        uint           `gorm:"primarykey" json:"id"`
	CreatedAt time.Time      `json:"created_at"`
	UpdatedAt time.Time      `json:"updated_at"`
	DeletedAt gorm.DeletedAt `gorm:"index" json:"deleted_at"`
	Username  string         `gorm:"uniqueIndex;size:50" json:"username"`
	Password  string         `gorm:"size:255" json:"-"`
	Email     string         `gorm:"size:100" json:"email"`
	Phone     string         `gorm:"size:20" json:"phone"`
	Status    int            `gorm:"default:1" json:"status"` // 1:正常 0:禁用
	Roles     []Role         `gorm:"many2many:user_roles;" json:"roles"`
}

type Role struct {
	ID          uint           `gorm:"primarykey" json:"id"`
	CreatedAt   time.Time      `json:"created_at"`
	UpdatedAt   time.Time      `json:"updated_at"`
	DeletedAt   gorm.DeletedAt `gorm:"index" json:"deleted_at"`
	Name        string         `gorm:"uniqueIndex;size:50" json:"name"`
	Description string         `gorm:"size:200" json:"description"`
	Permissions []Permission   `gorm:"many2many:role_permissions;" json:"permissions"`
	Users       []User         `gorm:"many2many:user_roles;" json:"users"`
}

type Permission struct {
	ID          uint           `gorm:"primarykey" json:"id"`
	CreatedAt   time.Time      `json:"created_at"`
	UpdatedAt   time.Time      `json:"updated_at"`
	DeletedAt   gorm.DeletedAt `gorm:"index" json:"deleted_at"`
	Name        string         `gorm:"uniqueIndex;size:50" json:"name"`
	Code        string         `gorm:"uniqueIndex;size:100" json:"code"`
	Description string         `gorm:"size:200" json:"description"`
	Type        int            `gorm:"default:1" json:"type"` // 1:菜单 2:按钮 3:接口
	ParentID    uint           `gorm:"default:0" json:"parent_id"`
	Path        string         `gorm:"size:200" json:"path"`
	Method      string         `gorm:"size:10" json:"method"`
	Roles       []Role         `gorm:"many2many:role_permissions;" json:"roles"`
}